package com.useeinfo.oa.modules.task.biz;

import com.useeinfo.framework.extend.biz.CrudBiz;
import com.useeinfo.oa.common.utils.ResultUtil.ResultDto;
import com.useeinfo.oa.common.utils.ResultUtil.ResultUtil;
import com.useeinfo.oa.modules.task.dao.TaskAuditOrderDao;
import com.useeinfo.oa.modules.task.entity.TaskAuditOrder;
import com.useeinfo.oa.modules.task.entity.TaskOrder;
import com.useeinfo.oa.modules.security.entity.SystemUser;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class TaskAuditOrderBiz extends CrudBiz<TaskAuditOrderDao, TaskAuditOrder> {

    /**
     * 保存审批记录
     * @param taskOrder
     * @param systemUser
     * @param pass
     * @param reason
     * @param level
     * @return
     */
    public ResultDto saveOrUpdate(TaskOrder taskOrder, SystemUser systemUser, boolean pass,String remark, String reason, int level){
        TaskAuditOrder insAuditOrder = new TaskAuditOrder();
        insAuditOrder.setCreateDate(new Date());
        insAuditOrder.setAuditDate(new Date());
        insAuditOrder.setLevel(level);
        insAuditOrder.setAuditUser(systemUser);
        insAuditOrder.setPass(pass);
        insAuditOrder.setEnterprise(taskOrder.getEnterprise());
        insAuditOrder.setRemark(remark);
        insAuditOrder.setTaskOrder(taskOrder);
        if(!pass){
            insAuditOrder.setReason(reason);
            insAuditOrder.setEffective(false);
        }
        dao.add(insAuditOrder);
        return ResultUtil.success();
    }
}
